from selenium.webdriver.common.by import By
from utils.webdriver_util import wait_element


class LoginPage:
    def __init__(self, driver):
        self.driver = driver

    # 定位元素
    def get_username_field(self):
        return wait_element(self.driver, By.XPATH, '//*[@id="app"]/div/div/form/div[1]/div/div/input')

    def get_password_field(self):
        return wait_element(self.driver, By.XPATH, '//*[@id="app"]/div/div/form/div[2]/div/div/input')

    def get_login_button(self):
        return wait_element(self.driver, By.XPATH, '//*[@id="app"]/div/div/form/div[3]/div/button/span')

    def login(self, username, password):
        self.get_username_field().send_keys(username)
        self.get_password_field().send_keys(password)
        self.get_login_button().click()
